﻿using System.Net;
using System.Net.Sockets;

namespace WebApiSampleTemplate.Extensions.Utils
{
    public static class StringUtil
    {
        public static string GetLocalIpAddress()
        {
            var host = Dns.GetHostEntry(Dns.GetHostName());
            if (host == null || host.AddressList.IsEmpty())
            {
                return string.Empty;
            }

            return host.AddressList
                .Where(x => x.AddressFamily == AddressFamily.InterNetwork)
                .Select(x => x.ToString())
                .FirstOrDefault();
        }
    }
}
